/* Siberian Olympiad. 2 stage.
  Problemset: http://agul-problems1.googlecode.com/svn/trunk/2010-2011/wso/stage2/wso_2stage.pdf
  Problem 7.
  Points: 100
*/
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
using namespace std;
const short maximum = 380;
class longs {
private:
	short chislo[maximum],size;
public:
	longs operator+ (const longs gur) const {
		longs res;
		for (int i=0; i<=max(gur.size,size); i++) res.chislo[i]=0;
		for (int i=0; i<max(gur.size,size); i++) {
			res.chislo[i+1]=(chislo[i]+gur.chislo[i]+res.chislo[i]) / 10;
			res.chislo[i]=(chislo[i]+gur.chislo[i]+res.chislo[i]) % 10;
		}
		res.size=max(gur.size,size);
		if (res.chislo[res.size]) res.size++;
		return res;
	}
	longs operator- (const longs gur) const {
		longs res;
		for (int i=0; i<=max(gur.size,size); i++) res.chislo[i]=0;
		short sub=0;
		for (int i=0; i<size; i++) {
			if (chislo[i]-sub-gur.chislo[i]>=0) {
				res.chislo[i]=chislo[i]-sub-gur.chislo[i];
				sub=0;
			} else {
				res.chislo[i]=chislo[i]-sub-gur.chislo[i]+10;
				sub=1;
			}
		}
		res.size=size;
		while (res.chislo[res.size-1]==0 && res.size>1) res.size--;
		return res;
	}
	bool operator< (const longs gur) const {
		if (size==gur.size) {
			for (int i=size-1; i>=0; i--) {
				if (chislo[i]!=gur.chislo[i]) return chislo[i]<gur.chislo[i];
			}
			return false;
		}
		return size<gur.size;
	}
	bool operator== (const longs gur) const {
		if (size==gur.size) {
			for (int i=size-1; i>=0; i--) {
				if (chislo[i]!=gur.chislo[i]) return false;
			}
			return true;
		}
		return false;
	}
	void print() {
		for (int i=size-1; i>=0; i--) 
			cout << chislo[i];
		cout << endl;
	}
	short length () {
		return size;
	}
	longs() {
		size=1;
		for (int i=0; i<maximum; i++) chislo[i]=0;
	}
	longs (char *s) {
		size=strlen(s);
		for (int i=0; i<size; i++)
			chislo[i]=s[size-i-1]-'0';
		for (int i=size; i<maximum; i++)
			chislo[i]=0;
	}
	longs (int a) {
		size=0;
		while (a!=0) {
			chislo[size++]=a % 10;
			a /= 10;
		}
		for (int i=size; i<maximum; i++) chislo[i]=0;
		if (!size) size=1;
	}
	
		
};
			
class bashnya {
	longs a,b,c;
public: 
	bashnya () {};
	bashnya (longs newa, longs newb, longs newc) {
		a=newa;
		b=newb;
		c=newc;
	}
	bashnya (int newa, int newb, int newc) {
		a=longs(newa);
		b=longs(newb);
		c=longs(newc);
	}
	bashnya operator+ (const bashnya add) const {
		return bashnya(a+add.a,b+add.b,c+add.c);
	}
	bashnya operator- (const bashnya sub) const {
		return bashnya(a-sub.a,b-sub.b,c-sub.c);
	}
	void print() {
		a.print();
		b.print();
		c.print();
	}
	longs sum() {
		return a+b+c;
	}
	bashnya ab () {
		return bashnya(a,c,b);
	}
	bashnya bc () {
		return bashnya(b,a,c);
	}
} count_new[1500];


longs smena (int n) {
	if (n==1) return 2;
	return count_new[n-1].sum()+2;
}

void fill (int n) {
	count_new[1]=bashnya(1,0,1);
	for (int i=2; i<=n; i++) {
		count_new[i]=count_new[i-1]+count_new[i-1];
		if (!(i % 2)) count_new[i]=count_new[i]+bashnya(0,2,0);
		if (i % 2) count_new[i]=count_new[i]+bashnya(1,0,1);
	}
}

int temp=0;

bashnya rec (int n, longs a) {
	temp=n;
	if (n==0 || a==0) return bashnya(0,0,0);
	if (n==1)  return bashnya(1,0,1);
	if (a<smena(n-1)) return rec(n-1,a).ab();
	if (a==smena(n-1)) return count_new[n - 1].ab()+bashnya(1,0,1);
	if (a==smena(n)-1) return count_new[n - 1].ab()+bashnya(1,0,1)+count_new[n-1].bc();
	return count_new[n-1].ab()+bashnya(1,0,1) + rec(n-1,a-smena(n-1)).bc();  	
}


int main () {
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);	
	int n;
	char st[maximum],st2[maximum];
	cin >> n;
	fill(n+1);
	scanf("%s%s",&st,&st2);
	(rec(n,st2)-rec(n,longs(st)-longs(1))).print();
	return 0;
}


